<template>
	<view class="content">
		<view class="address">
			<view class="address_cont">
				<view class="address_icon">
					<image src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/addr.png" mode=""></image>
				</view>
				<view class="address_detail" v-if="Object.keys(yxUserAddress).length == 0 " @click="selectAddress">添加收货地址</view>
				<view class="address_detail" v-else @click="selectAddress">
					<view class="address_name">
						<view class="name">{{yxUserAddress.realName}}</view>
						<view class="phone">{{yxUserAddress.phone}}</view>
					</view>
					<view class="address_info">{{yxUserAddress.province}}{{yxUserAddress.city}}{{yxUserAddress.district}}{{yxUserAddress.detail}}</view>
				</view>
				<view class="iconfont select_icon">&#xe601;</view>
			</view>

		</view>
		<!-- <view class="group">
			<view class="goods" v-for="(item,index) in orderDatas.cartInfo">
				<view class="goods_image">
					<image :src="item.productInfo.image" mode=""></image>
				</view>
				<view class="goods_cont">
					<view class="goods_name ellipsis_2">{{item.productInfo.storeName}}</view>
					<view class="goods_bot">
						<view class="goods_price">
							<view class="sign iconfont">&#xe604;</view>
							<view class="price">
								{{item.productInfo.attrInfo.price}} <text > +{{item.productInfo.attrInfo.integral}}通宝</text>
							</view>
						</view>
						<view class="goods_num">X{{item.cartNum}}</view>
					</view>
				</view>
			</view>
		</view> -->

		<view class="bottom">
			<view class="submit" @click="sureOrder">确认</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderDatas: {},
				yxUserAddress: {},
				userAddressId: '',
				cartId: '', // 购物车id
				totalPrice: '',
				orderKey: '', // 订单key值
				totalIntegral: '',
				addressDetail:''
			}
		},
		onLoad(options) {
			console.log(options)
			if (Object.keys(options).length != 0) {
				this.id = options.id;
			}
			let that = this;
			uni.$on('giftAddress', function(data) {
				console.log('监听到事件来自 giftAddress ，携带参数 msg 为：' + data.msg);
				that.getUserAddress();
			})
		},
		onUnload() {
			uni.$off('giftAddress')
		},
		methods: {
			// 选择地址
			selectAddress: function() {
				uni.navigateTo({
					url: '../../address/address?addressType=2',
				});
			},
			// 根据地址id获取地址
			getUserAddress: function() {
				let that = this;
				that.api.getUserAddressDetail(that.userAddressId).then(res => {
					console.log(res)
					that.yxUserAddress = res.data;
					that.addressDetail = res.data.province + res.data.city + res.data.district + res.data.detail
				})
			},
			// 提交订单
			sureOrder: function() {
				let that = this;
				if (that.userAddressId == '') {
					that.tui.toast('请选择地址');
					return
				}
				that.api.depositDrawRecord({
					id:that.id,
					userAddress:that.userAddressId
				}).then(res => {
					console.log(res,"----")
					that.tui.toast(res.data)
					setTimeout(function () {
						uni.$emit('updateDraw',{msg:'领取奖品'})
					},500)
					
				})
				
				// if (that.userAddressId == '') {
				// 	that.tui.toast('请选择收货地址')
				// 	return
				// }
				// that.api.userCreationOrder(that.orderKey,{
				// 	mark:'',
				// 	addressId:that.userAddressId
				// }).then(res => {
				// 	console.log(res)
				// 	that.tui.toast(res.msg);
				// 	let orderPay = JSON.stringify(res.data.result);
				// 	// let orderInfo = JSON.stringify(orderPay)
				// 	console.log(orderPay)
				// 	setTimeout(function () {
				// 		// uni.$emit('shoppingCar',{msg:'页面更新'});
				// 	},500)

				// })
			}
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		letter-spacing: 3rpx;
		font-family: PingFang SC;
		color: #140005;
		font-size: 28rpx;
		padding: 20rpx;
	}

	.content {
		width: 100%;
		box-sizing: border-box;
	}

	.address {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 30rpx 22rpx;
		border-radius: 12rpx;
		margin-bottom: 20rpx;

		.address_cont {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #666666;

			.address_icon {
				width: 28rpx;
				height: 28rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.select_icon {
				width: 30rpx;
				box-sizing: border-box;
				text-align: center;
				font-size: 30rpx;
				color: #999999;
			}

			.address_detail {
				width: calc(100% - 60rpx);
				box-sizing: border-box;
				padding: 15rpx 0 15rpx 20rpx;

				.address_name {
					width: 100%;
					box-sizing: border-box;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					line-height: 60rpx;

					.name {
						padding-right: 30rpx;
					}
				}

				.address_info {
					width: 100%;
					box-sizing: border-box;
					// padding-top: 15rpx;
				}
			}

		}
	}

	.group {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 0 22rpx;
		border-radius: 12rpx;

		.goods {
			width: 100%;
			box-sizing: border-box;
			padding: 30rpx 0;
			display: flex;
			justify-content: space-between;
			border-bottom: 2rpx solid #F5F5F5;

			.goods_image {
				width: 160rpx;
				height: 160rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 16rpx;
				}
			}

			.goods_cont {
				width: calc(100% - 160rpx);
				box-sizing: border-box;
				padding-left: 20rpx;
				display: flex;
				flex-flow: column;
				justify-content: space-between;

				.goods_bot {
					width: 100%;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 22rpx;
					color: #212121;

					.goods_price {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						color: #E42221;

						.price {
							font-size: 28rpx;
						}
					}
				}

				.goods_name {
					width: 100%;
					box-sizing: border-box;
					line-height: 40rpx;
				}
			}
		}

		.freight {
			width: 100%;
			box-sizing: border-box;
			line-height: 100rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}

	.bottom {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 99;
		display: flex;
		justify-content: flex-end;
		align-items: center;

		.submit {
			width: 236rpx;
			height: 100rpx;
			box-sizing: border-box;
			text-align: center;
			font-size: 36rpx;
			line-height: 100rpx;
			color: #FFFFFF;
			background: #E42221;
		}

		.bottom_total {
			width: calc(100% - 236rpx);
			box-sizing: border-box;
			padding-right: 53rpx;
			font-size: 28rpx;
			color: #E42221;
			text-align: right;
			font-weight: 500;
		}
	}
</style>
